using System;
using System.Collections.Generic;
using System.Text;

namespace GoogleCalendarReminder
{
    /// <summary>
    /// A class which enables/disables program startup upon Windows startup.
    /// </summary>
    public class StartupManager
    {
        private static Microsoft.Win32.RegistryKey _runKey =
            Microsoft.Win32.Registry.CurrentUser.CreateSubKey(
            @"Software\Microsoft\Windows\CurrentVersion\Run");

        private static readonly string _keyName = "Google Calendar Reminder";

        /// <summary>
        /// Gets or sets whether or not the program should startup upon Windows startup.
        /// </summary>
        public static bool StartWithWindows
        {
            get
            {
                object val = _runKey.GetValue(_keyName);

                if (val == null || !val.ToString().Equals(System.Windows.Forms.Application.ExecutablePath))
                {
                    return false;
                }

                return true;
            }
            set
            {
                if (value)
                {
                    _runKey.SetValue(_keyName, System.Windows.Forms.Application.ExecutablePath);
                }
                else
                {
                    _runKey.DeleteValue(_keyName);
                }
            }
        }
    }
}
